package com.marion.langchain4jdemo.controller;


import com.marion.langchain4jdemo.service.QWen;
import dev.langchain4j.model.chat.ChatLanguageModel;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import static org.springframework.http.MediaType.TEXT_EVENT_STREAM_VALUE;

@RestController
public class chat2QW_plus {

    @Resource
    private QWen qWen;

//    @Autowired
//    @Qualifier("Qwen01")
//    private QWen qWen01;

    // 创建一个实例对象用于调用接口
    private ChatLanguageModel chatLanguageModel;

    // 创建一个构造函数，这样会自动创建一个OpenAiChatModel的对象，不需要我们手动创建
    public chat2QW_plus(ChatLanguageModel chatLanguageModel) {
        this.chatLanguageModel = chatLanguageModel;
    }

    @GetMapping("/chat")
    public String model(@RequestParam(value = "message", defaultValue = "Hello") String message) {
        return chatLanguageModel.chat(message);
    }

    @GetMapping("/chat2")
    public String model2(@RequestParam(value = "message", defaultValue = "算法的特性是什么") String message) {
        return qWen.chat(message);
    }

    @GetMapping(value = "/chatWithStream", produces = TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chatWithStream(@RequestParam(value = "message", defaultValue = "算法的特性是什么") String message) {
        return qWen.chatWithStream(message);
    }

    @GetMapping(value = "/chatWithMemory", produces = TEXT_EVENT_STREAM_VALUE)
    public String chatWithMemory(@RequestParam(value = "message", defaultValue = "算法的特性是什么") String message,
                                 @RequestParam("userid") String userid) {
//        return qWen01.chatWithMemory(userid, message);
        return "";
    }
}
